package com.hanrui.android.fragment.message.audit.yearplan;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hanrui.android.R;
import com.hanrui.android.library.base.BaseFragment;
import com.hanrui.android.model.YearPlanDetailBean;
import com.hanrui.android.model.YearPlanListBean;
import com.hanrui.android.net.contract.message.audit.yearplan.YearPlanDetailContract;
import com.hanrui.android.net.presenter.message.audit.yearplan.YearPlanDetailPresenter;

import butterknife.BindView;

/**
 * 年度绩效基本信息
 *
 */

public class YearPlanDetailFragment extends BaseFragment<YearPlanDetailPresenter> implements YearPlanDetailContract.View {
    @BindView(R.id.main_title)
    TextView mainTitle;
    @BindView(R.id.subhead_title)
    TextView subheadTitle;
    @BindView(R.id.thing_title)
    TextView thingTitle;
    @BindView(R.id.time)
    TextView time;
    @BindView(R.id.page_num)
    TextView pageNum;
    @BindView(R.id.ll_addview)
    LinearLayout lladdview;

    String taskId,procInsId,bizId;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_yearplandetail;
    }

    @Override
    protected void initInjector() { mFragmentComponent.inject(this); }

    @Override
    protected void initView(View view) {

        taskId = getArguments().getString("taskId");
        procInsId = getArguments().getString("procInsId");
        bizId = getArguments().getString("bizId");

        mPresenter.yearPlanBizDetail(getActivity(),taskId,procInsId,bizId);

    }



    public static YearPlanDetailFragment newInstance(String taskId, String procInsId, String bizId) {
        YearPlanDetailFragment fragment = new YearPlanDetailFragment();
        Bundle bundle = new Bundle();
        bundle.putString("taskId", taskId);
        bundle.putString("procInsId", procInsId);
        bundle.putString("bizId", bizId);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void yearPlanBizDetail(final YearPlanDetailBean data) {

        if (null != data) {

            mainTitle.setText("员工绩效目标分解表");
            subheadTitle.setText(data.getDetail().getCreateDate());

            thingTitle.setText(data.getDetail().getOfficeName());
            time.setText(data.getDetail().getUserTypeName());
            pageNum.setText(data.getDetail().getCreateDate());

            lladdview.setVisibility(View.VISIBLE);

            if (null != data.getDetail().getYearPlan1List() && data.getDetail().getYearPlan1List().size() > 0) {

                for (int i = 0; i < data.getDetail().getYearPlan1List().size(); i++) {

                    if (i == 0) {

                        addViewItem(data.getDetail().getYearPlan1List().get(i),true);

                    }else {

                        addViewItem(data.getDetail().getYearPlan1List().get(i), false);
                    }

                }
            }


            if (null != data.getDetail().getYearPlan2List() && data.getDetail().getYearPlan2List().size() > 0) {

                for (int i = 0; i < data.getDetail().getYearPlan2List().size(); i++) {

                    if (i == 0) {

                        addViewItem(data.getDetail().getYearPlan2List().get(i),true);

                    }else {

                        addViewItem(data.getDetail().getYearPlan2List().get(i), false);
                    }

                }

            }


            if (null != data.getDetail().getYearPlan3List() && data.getDetail().getYearPlan3List().size() > 0) {

                for (int i = 0; i < data.getDetail().getYearPlan3List().size(); i++) {

                    if (i == 0) {

                        addViewItem(data.getDetail().getYearPlan3List().get(i),true);

                    }else {

                        addViewItem(data.getDetail().getYearPlan3List().get(i), false);
                    }

                }

            }

        }

    }


    //添加ViewItem
    private void addViewItem(final YearPlanListBean bean, boolean isShow) {
        View hotelEvaluateView = View.inflate(getActivity(), R.layout.item_yearplandetail, null);
        TextView minTitle = hotelEvaluateView.findViewById(R.id.min_title);
        TextView name = hotelEvaluateView.findViewById(R.id.name);
        TextView workContent = hotelEvaluateView.findViewById(R.id.work_content);
        TextView workContenter = hotelEvaluateView.findViewById(R.id.work_contenter);
        TextView workContentthree = hotelEvaluateView.findViewById(R.id.work_contentthree);
        TextView workContentfour = hotelEvaluateView.findViewById(R.id.work_contentfour);
        TextView check = hotelEvaluateView.findViewById(R.id.check);
        TextView score = hotelEvaluateView.findViewById(R.id.score);

        if (isShow) {

            minTitle.setText(bean.getProjectContent()+bean.getRate()+"%");
            minTitle.setVisibility(View.VISIBLE);
        }else {
            minTitle.setVisibility(View.GONE);
        }

        name.setText(bean.getAllYearPlan());
        workContent.setText(bean.getFirstQuarterPlan());
        workContenter.setText(bean.getSecondQuarterPlan());
        workContentthree.setText(bean.getThirdQuarterPlan());
        workContentfour.setText(bean.getFourthQuarterPlan());
        check.setText(bean.getRules());
        score.setText(bean.getScore());

        lladdview.addView(hotelEvaluateView);
    }


}
